import Utils from "./utils.js"

function Watcher (vm, key, cb) {
  this.vm = vm
  this.key = key
  this.cb = cb
  this.oldValue = Utils.getValue(vm, key)
}

Watcher.prototype.update = function () {
  // this.vm.$option.beforeUpdate()
  const newVal = Utils.getValue(this.vm, this.key)
  if (this.oldValue !== newVal) {
    this.cb(newVal)
  }
  // this.vm.$option.updated()
}

export default Watcher
